package com.yuliang.controller;


import com.yuliang.constants.SystemConstants;
import com.yuliang.domain.R;
import com.yuliang.domain.dto.AddCommentDto;
import com.yuliang.domain.entity.Comment;
import com.yuliang.service.CommentService;
import com.yuliang.utils.BeanCopyUtils;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/comment")
@Api(description = "评论相关接口")
public class CommentController {

    @Resource
    private CommentService commentService;

    @GetMapping("/commentList")
    public R getCommentList(Long articleId,Integer pageNum,Integer pageSize){
        return commentService.getCommentList(SystemConstants.ARTICLE_COMMENT,articleId,pageNum,pageSize);
    }

    @PostMapping
    public R comment(@RequestBody AddCommentDto addCommentDto){
        Comment comment = BeanCopyUtils.copyBean(addCommentDto, Comment.class);
        return commentService.comment(comment);
    }

    @GetMapping("/linkCommentList")
    public R getLinkCommentList(Long articleId,Integer pageNum,Integer pageSize){
        return commentService.getCommentList(SystemConstants.LINK_COMMENT,articleId,pageNum,pageSize);
    }
}
